<script type="text/javascript" >
  $(function() {
    $( "#start" ).datepicker();
    $( "#end" ).datepicker();
  });
</script>

<fieldset>
  <legend><h3>选择统计时间段</h3></legend>
  <%=form_tag('/posts/period', :method =>"get")%>
  开始日期:<input type="text" id="start" name="post[start]" />
  结束日期:<input type="text" id="end" name="post[end]" />
  <div><%= submit_tag '确定' %></div>
</form>
</fieldset>
<%if params[:post] && !params[:post][:start].blank? && !params[:post][:end].blank? %>
  <h3>文章时间段统计</h3>
  <table cellpadding="0" cellspacing="0" class="admin">
    <caption><h3>按科组</h3></caption>
    <tr>
      <th>科组</th>
      <th>统计</th>
    </tr>
    <tbody>
      <%  org_list.each do |cur_org| %>
        <tr>
          <th class="spec period-first-col"><%=  cur_org[0] %></th>
          <td>
            <%=Post.where(:created_at =>@times[0]..@times[1],:org_id=>cur_org[1]).count()%>
          </td>
        </tr>
      <%  end %>
    </tbody>
  </table>

  <table cellpadding="0" cellspacing="0" class="admin">
    <caption><h3>按工会小组</h3></caption>
    <tr>
      <th>年级</th>
      <th>统计</th>
    </tr>
    <tbody>
      <%  grade_list.each do |cur_g| %>
        <tr>
          <th class="spec period-first-col"><%=  cur_g[0] %></th>
          <td>
            <%=Post.where(:created_at =>@times[0]..@times[1],:grade=>cur_g[1]).count()%>
          </td>
        </tr>
      <%  end %>
    </tbody>
  </table>

  <table cellpadding="0" cellspacing="0" class="admin">
    <caption><h3>按账号</h3></caption>
    <tr>
      <th>账号</th>
      <th>统计</th>
    </tr>
    <tbody>
      <%  User.all.each do |cur_u| %>
        <tr>
          <th class="spec period-first-col"><%=  cur_u.user_name %></th>
          <td>
            <%=Post.where(:created_at =>@times[0]..@times[1],:user_id => cur_u.id).count()%>
          </td>
        </tr>
      <%  end %>
    </tbody>
  </table>

  <table cellpadding="0" cellspacing="0" class="admin">
    <caption><h3>按作者</h3></caption>
    <tr>
      <th>作者</th>
      <th>统计</th>
    </tr>
    <tbody>
      <%  Post.select("author,count(id) as 'count'").group("author").each do |r| %>
        <tr>
          <th class="spec period-first-col">
            <%=r.author%>
          </th>

          <td>
            <%=r.count%>
          </td>
        </tr>
      <%  end %>
    </tbody>
  </table>
<%else%>
  请选择正确的时间
<% end %>